﻿#ifndef FD_CORE_UTF8STRING_H
#define FD_CORE_UTF8STRING_H
#pragma once
#include "kernel/multibytestring.h"

namespace FD
{
	namespace Kernel
	{
		class FD_Kernel_Export FdUtf8String : public FdMultiByteString
		{
		public:
			/// <summary>
			// 构造函数
			/// </summary>
			/// <param name="&ch">初始化当前对象的FdChar字符</param>
			/// <param name="*pMultiByteStr">初始化当前对象的多字节字符串</param>
			/// <param name="*pUnicodeStr">初始化当前对象的Unicode字符串</param>
			/// <param name="&str">初始化当前对象的FdMultiByteString对象</param>
			/// <param name="&wstr">初始化当前对象的FdUnicodeString对象</param>
			/// <returns></returns>
			FdUtf8String();
			FdUtf8String( const CHAR &ch);
			FdUtf8String( const FdChar  &ch);        
			FdUtf8String( const CHAR  *pMultiByteStr);
			FdUtf8String( const WCHAR *pUnicodeStr);
			FdUtf8String(const FdUtf8String &str);
			FdUtf8String(const FdUnicodeString &wstr);
			FdUtf8String(const FdMultiByteString &strMultiByte);

			FdUtf8String& assign(const CHAR* ptr,size_type offset,size_type count)
			{
#ifdef __OS_WIN__
				m_strDataBuffer.assign(FdUtf8String(ptr).c_str(),offset,count);
#else
				m_strDataBuffer.assign(ptr,offset,count);
#endif
				return *this;
			}

			FdUtf8String& assign(const CHAR* ptr,size_type count)
			{
#ifdef __OS_WIN__
				m_strDataBuffer.assign(FdUtf8String(ptr).c_str(),count);
#else
				m_strDataBuffer.assign(ptr,count);
#endif
				return *this;
			}

			/// <summary>
			// 设置当前对象的字符串值
			/// </summary>
			/// <param name="pMultiByteStr">指定的多字节字符串值</param>
			/// <param name="pUnicodeStr">指定的Unicode字符串值</param>
			/// <returns></returns>
			void setString( const CHAR  *pMultiByteStr);
			void setString( const WCHAR *pUnicodeStr);
			/// <summary>
			// 在当前字符串对象末尾追加数据
			/// </summary>
			/// <param name="ch">追加FdChar字符</param>
			/// <param name="pMultiByteStr">追加char*的字符串</param>
			/// <param name="pUnicodeStr">追加Unicode字符串</param>
			/// <param name="nCount">从缓冲区中指定的字符数目</param>
			/// <param name="strMultiByte">char*的字符串</param>
			/// <param name="strUnicode">Unicode的字符串</param>
			/// <returns>返回追加后的当前字符串对象的引用</returns>
			FdUtf8String&  append( const FdChar  &ch);
			FdUtf8String&  append( const CHAR  *pMultiByteStr);
			FdUtf8String&  append( const WCHAR *pUnicodeStr);
			FdUtf8String&  append( const CHAR  *pMultiByteStr,  size_t nCount);
			FdUtf8String&  append( const WCHAR *pUnicodeStr,  size_t nCount);
			FdUtf8String&  append( const FdMultiByteString  &strMultiByte);
			FdUtf8String&  append( const FdUnicodeString    &strUnicode);
			FdUtf8String&  append( const CHAR ch);
			FdUtf8String&  append( const FdUtf8String &ch);

			/// <summary>
			// 在当前字符串对象的指定位置插入数据
			/// </summary>
			/// <param name="nIndexOfPos">插入字符串的位置</param>
			/// <param name="ch">插入FdChar字符</param>
			/// <param name="pMultiByteStr">插入char*的字符串</param>
			/// <param name="pUnicodeStr">插入Unicode字符串</param>
			/// <returns>返回插入新数据后的当前字符串对象的引用</returns>
			virtual FdUtf8String&  insert( size_t nIndexOfPos,  const FdChar  &ch);
			virtual FdUtf8String&  insert( size_t nIndexOfPos,  const CHAR  *pMultiByteStr);
			virtual FdUtf8String&  insert( size_t nIndexOfPos,  const WCHAR *pUnicodeStr);

			/// <summary>
			// 格式化当前字符串
			/// </summary>
			/// <param name="pFormatStr">格式化的描述字符串</param>
			/// <param name="pFormatWStr">格式化的描述字符串</param>
			/// <returns>返回格式化完成后的当前字符串对象的引用</returns>
			virtual FdUtf8String&  format( const CHAR  *pFormatStr,  ...); 
			virtual FdUtf8String&  format( const WCHAR *pFormatWStr,  ...);

			/// <summary>
			// 生成指定的格式化字符串并追加到当前字符串末尾
			/// </summary>
			/// <param name="pFormatStr">格式化的描述字符串</param>
			/// <param name="pFormatWStr">格式化的描述字符串</param>
			/// <returns>返回格式化完成后的当前字符串对象的引用</returns>
			virtual FdUtf8String&  formatAppend( const CHAR  *pFormatStr, ...); 
			virtual FdUtf8String&  formatAppend( const WCHAR *pFormatWStr, ...);

			/// <summary>
			// 赋值操作符重载
			/// </summary>
			/// <param name="ch">单个FdChar字符</param>
			/// <param name="pMultiByteStr">CHAR型字符串</param>
			/// <param name="pUnicodeStr">WCHAR型字符串</param>
			/// <param name="strMultiByte">多字节字符串对象</param>
			/// <param name="strUnicode">Unicode字符串对象</param>
			/// <returns>返回当前对象的引用</returns>
			FdUtf8String&  operator=( const FdChar  &ch);
			FdUtf8String&  operator=( const CHAR  *pMultiByteStr);
			FdUtf8String&  operator=( const WCHAR *pUnicodeStr);
			FdUtf8String&  operator=( const FdMultiByteString &strMultiByte);
			FdUtf8String&  operator=( const FdUnicodeString &strUnicode);
			FdUtf8String&  operator=( const std::string    &strMultiByte);
			FdUtf8String&  operator=( const wchar_string   &strUnicode);
			FdUtf8String&  operator=( const FdUtf8String   &strUtf);

			/// <summary>
			// +号操作符重载
			/// </summary>
			/// <param name="ch">单个FdChar字符</param>
			/// <param name="strMultiByte">FdMultiByteString对象</param>
			/// <param name="strUnicode">FdUnicodeString对象</param>
			/// <param name="pMultiByteStr">CHAR型字符串</param>
			/// <param name="pUnicodeStr">WCHAR型字符串</param>
			/// <returns>返回相加后的FdMultiByteString对象</returns>
			friend FD_Kernel_Export FdUtf8String  operator+( const FdUtf8String &strUtfL,  const FdUtf8String &strUtfR); 
			friend FD_Kernel_Export FdUtf8String  operator+( const FdUtf8String &strUtf,  const FdUnicodeString strUnicode);
			friend FD_Kernel_Export FdUtf8String  operator+( const FdChar  &ch,  const FdUtf8String &strUtf);
			friend FD_Kernel_Export FdUtf8String  operator+( const FdUtf8String &strUtf,  const FdChar  &ch);
			friend FD_Kernel_Export FdUtf8String  operator+( const CHAR* pMultiByteStr,  const FdUtf8String &strUtf);
			friend FD_Kernel_Export FdUtf8String  operator+( const FdUtf8String &strUtf,  const CHAR* pMultiByteStr);
			friend FD_Kernel_Export FdUtf8String  operator+( const WCHAR* pUnicodeStr,  const FdUtf8String &strUtf);
			friend FD_Kernel_Export FdUtf8String  operator+( const FdUtf8String &strUtf,  const WCHAR* pUnicodeStr);
			//friend FD_Kernel_Export FdUtf8String  operator+( const CHAR* pMultiByteStr,  const FdChar  &ch);
			//friend FD_Kernel_Export FdUtf8String  operator+( const FdChar  &ch,  const CHAR* pMultiByteStr);

			/// <summary>
			// +=运算符重载
			/// </summary>
			/// <param name="ch">单个FdChar字符</param>
			/// <param name="strMultiByte">FdMultiByteString对象</param>
			/// <param name="strUnicode">FdUnicodeString对象</param>
			/// <param name="pMultiByteStr">CHAR型字符串</param>
			/// <param name="pUnicodeStr">WCHAR型字符串</param>
			/// <returns>返回相加后的FdMultiByteString对象</returns>
			FdUtf8String&  operator+=( const FdUtf8String  &strUtf);
			FdUtf8String&  operator+=( const FdChar  &ch);
			FdUtf8String&  operator+=( const CHAR  *pMultiByteStr);
			FdUtf8String&  operator+=( const WCHAR *pUnicodeStr);
			FdUtf8String&  operator+=( const FdMultiByteString &strMultiByte);
			FdUtf8String&  operator+=( const FdUnicodeString &strUnicode);
			FdUtf8String&  operator+=( const CHAR &ch);

			/// <summary>
			// 等于操作符重载
			/// </summary>
			/// <param name="ch">单个FdChar字符</param>
			/// <param name="strMultiByte">FdMultiByteString对象</param>
			/// <param name="strUnicode">FdUnicodeString对象</param>
			/// <param name="pMultiByteStr">CHAR型字符串</param>
			/// <param name="pUnicodeStr">WCHAR型字符串</param>
			/// <returns>如果两边相等返回true，否则返回false</returns>
			bool operator==( const FdChar  &ch) const;
			bool operator==( const CHAR  *pMultiByteStr) const;
			bool operator==( const WCHAR *pUnicodeStr) const;
			bool operator==( const FdMultiByteString &strMultiByte) const;
			bool operator==( const FdUnicodeString &strUnicode) const;
			bool operator==( const FdUtf8String  &strUtf) const;

			operator   FdMultiByteString();
			FdUtf8String& assignFromUtf8Charset(const CHAR*Utf8str);
			static FdMultiByteString fromUtf8toMutiByteString( const CHAR* ch);
		};
	}
}
#endif